package com.cn.wanxi.servlet;

import com.alibaba.fastjson.JSONObject;
import com.cn.wanxi.model.FileModel;
import com.cn.wanxi.model.ResultModel;
import com.cn.wanxi.util.FileUpload;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/upload")
public class UploadFileServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

        FileModel model = new FileModel();
        model.setSrc(FileUpload.upload(req));
        ResultModel resultModel = ResultModel.getResult(model);
        resp.getWriter().println(JSONObject.toJSONString(resultModel));
    }
}
